package com.zhsh.generator;

import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.zhsh.generator.template.engine.TemplateHandle;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

/**
 * @author xiaoyuhai
 * @description
 * @date 2019-04-28 15:03
 **/
public class StartUp {


    public static void main(String[] args) throws Exception {
        StartUp.createMybatis();

        StartUp.createTemplateCode();
    }

    /**
     * 生成mybatis文件
     */
    private static void createMybatis () throws Exception {
        List<String> warnings = new ArrayList<>();
        ClassLoader classloader = Thread.currentThread().getContextClassLoader();
        InputStream is = classloader.getResourceAsStream("generatorConfig.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(is);
        DefaultShellCallback callback = new DefaultShellCallback(true);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
        System.out.println("mybatis文件生成完成....................................！");
    }

    //创建业务代码
    private static void createTemplateCode() {
        //开始生成业务代码
        TemplateHandle templateHandle = new TemplateHandle();
        templateHandle.createTemplate();
        System.out.println("业务代码生成完成....................................！");
    }
}